package com.bye.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bye.annotation.Login;
import com.bye.dto.CustomerDto;
import com.bye.service.CustomerService;
import com.bye.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    @Login
    @RequestMapping("countCustomer")
    public Result countCustomer(){
        String result = customerService.countCustomer();
        return Result.success(result);
    }

    @RequestMapping("selectCustomersOfConsume")
    public Result selectCustomersOfConsume() {
        List<CustomerDto> list = customerService.selectCustomersOfConsume();
        return  Result.success().put("list",list);
    }

    @RequestMapping("showCustomer")
    public Result showCustomer(@RequestBody CustomerDto customerDto) {
        IPage<CustomerDto> customerList = customerService.showCustomer(customerDto);
        List<CustomerDto> list = customerList.getRecords();
        long total = customerList.getTotal();
        return Result.success().put("customerList",list).put("total",total);
    }

    //更改顾客的状态
    @RequestMapping("changeStatus")
    public Result changeStatus(@RequestBody CustomerDto customerDto) {
        int i = customerService.changeStatus(customerDto);
        if(i>0){
            return Result.success("修改成功");
        }else {
            return Result.error("修改失败");
        }
    }

    //根据手机号和时间查询顾客
    @RequestMapping("selectCustomerOfPhone")
    public  Result selectCustomerOfPhone(@RequestBody CustomerDto customerDto) {
        List<CustomerDto> list = customerService.selectCustomerOfPhone(customerDto);
        return Result.success().put("list",list);
    }
}
